package com.yupi.springbootinit.service.impl.search;

import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yupi.springbootinit.enums.SearchKeyWord;
import com.yupi.springbootinit.model.vo.PictureVo;
import lombok.SneakyThrows;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

import java.net.URL;

@Service
public class PictureSearchService implements SearchService<PictureVo> {

    @SneakyThrows
    @Override
    public Page<PictureVo> doSearch(String searchText, int pageSize, int pageNo) {
        String url = String.format("https://www.bing.com/images/search?q=%s&form=HDRSC2&first=%s", searchText, pageSize);
        Document document = Jsoup.connect(url).get();
        System.out.println("=========================" + document);
        for (Element element : document.select(".imgpt iusc")) {
            for (Element iusc : element.select(".iusc")) {
            }
        }
        return null;
    }

    @Override
    public SearchKeyWord getSearchKeyWord() {
        return SearchKeyWord.PICTURE;
    }


}
